<html>
<head>
<style>
  .ace_editor {
    border: 0;
    width: auto;
    height: 100%;
    margin: 0;
    top:0;
    right:0;
    bottom:0;
    left:0;
    z-index: 10000;
    touch-action: none;
  }

  body {
    padding: 0px;
    margin: 0px;
    overflow: hidden;
    -ms-overflow-style: scrollbar;
  }
</style>
</head>
<body>
<textarea id="source">package com.sencha.gxt.explorer.client.dnd;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.dom.client.Style.Overflow;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.sencha.gxt.core.client.util.Rectangle;
import com.sencha.gxt.explorer.client.app.ui.ExampleContainer;
import com.sencha.gxt.explorer.client.model.Example.Detail;
import com.sencha.gxt.fx.client.Draggable;
import com.sencha.gxt.widget.core.client.ContentPanel;
import com.sencha.gxt.widget.core.client.Resizable;
import com.sencha.gxt.widget.core.client.Resizable.Dir;
import com.sencha.gxt.widget.core.client.container.MarginData;
import com.sencha.gxt.widget.core.client.event.ResizeEndEvent;
import com.sencha.gxt.widget.core.client.event.ResizeEndEvent.ResizeEndHandler;

public class ResizableExample implements IsWidget, EntryPoint {

  protected static final int MAX_HEIGHT = 600;
  protected static final int MAX_WIDTH = 800;
  protected static final int MIN_HEIGHT = 240;
  protected static final int MIN_WIDTH = 320;

  private ContentPanel panel;

  @Override
  public Widget asWidget() {
    if (panel == null) {
      panel = new ContentPanel() {
        private Draggable draggable;
        private Resizable resizeable;

        @Override
        protected void onAfterFirstAttach() {
          super.onAfterFirstAttach();

          // draggable within the parent container
          draggable = new Draggable(this);

          // resizable in all directions with min/max sizes
          resizeable = new Resizable(this, Dir.E, Dir.N, Dir.NE, Dir.NW, Dir.S, Dir.SE, Dir.SW, Dir.W);
          resizeable.setPreserveRatio(false);
          resizeable.setMaxHeight(MAX_HEIGHT);
          resizeable.setMaxWidth(MAX_WIDTH);
          resizeable.setMinHeight(MIN_HEIGHT);
          resizeable.setMinWidth(MIN_WIDTH);
          resizeable.addResizeEndHandler(new ResizeEndHandler() {
            @Override
            public void onResizeEnd(ResizeEndEvent event) {
              // constrain resize to the parent container
              Rectangle r = getElement().adjustForConstraints(getParent().getElement(), getElement().getBounds());
              setPagePosition(r.getX(), r.getY());
              setPixelSize(r.getWidth(), r.getHeight());
            }
          });
        }

        @Override
        protected void onAttach() {
          super.onAttach();
          draggable.setContainer(getParent());
        }

        @Override
        protected void onCollapse() {
          // don't allow resizing while collapsed
          resizeable.setEnabled(false);

          super.onCollapse();
        }

        @Override
        protected void onExpand() {
          super.onExpand();

          // allow resizing while expanded
          resizeable.setEnabled(true);
        }
      };
      panel.setHeading("Collapse, Drag, Resize");
      panel.setCollapsible(true);
      panel.add(new Label("Collapse, drag and resize this box."), new MarginData(20));
    }

    return panel;
  }

  @Override
  public void onModuleLoad() {
    new ExampleContainer(this)
        .setMaxHeight(MAX_HEIGHT)
        .setMaxWidth(MAX_WIDTH)
        .setMinHeight(MIN_HEIGHT)
        .setMinWidth(MIN_WIDTH)
        .setOverflowX(Overflow.HIDDEN)
        .setOverflowY(Overflow.HIDDEN)
        .doStandalone();
  }

}
</textarea>

<script src="../../samples/ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
  var type = "{type}";
  if (type == ("{" + "type}")) {
    // something went wrong, use java as default
    type = "java";
  }
  var editor = ace.edit("source");
  var mode = "ace/mode/" + type;
  var theme = "ace/theme/chrome";
  var readOnly = true;
  editor.getSession().setMode(mode);
  editor.getSession().setUseWorker(false);
  editor.setTheme(theme);
  editor.setShowPrintMargin(false);
  editor.renderer.setShowGutter(true);
  editor.setHighlightActiveLine(false);
  editor.setDisplayIndentGuides(true);
  editor.setReadOnly(readOnly);
  editor.renderer.setPadding(10);
  editor.renderer.setScrollMargin(10, 10, 0, 0);
  editor.getSession().setOptions({
    tabSize: 8,
    useSoftTabs: true,
    useWrapMode: false,
  });
</script>
</body>
</html>